package org.esk.dablog.model.forum;

import org.esk.dablog.model.Entry;
import org.hibernate.annotations.Formula;

import javax.persistence.Entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Column;
import javax.persistence.Transient;
import java.util.Set;

/**
 * This class 
 * User: esk
 * Date: Dec 12, 2006
 * Time: 5:24:57 PM
 * $Id:$
 * @hibernate.subclass
 *   discriminator-value="4"
 */
@Entity
@DiscriminatorValue("4")
public class ForumPostEntry extends Entry {

    public static final int STATE_NORMAL = 0;
    public static final int STATE_COMMENTS_DISABLED = 1;
    public static final int STATE_HIDDEN = 1000;


    private long topicId;
    private int commentCount;

    /**
     * @hibernate.property
     *   formula="(select count(*) from comments c where c.entry_id = id)"
     * @return
     */
    @Formula("(select count(*) from comments c where c.entry_id = id)")
    public int getCommentCount() {
        return commentCount;
    }

    /**
     * @hibernate.property
     *   column="PARENT_ENTRY_ID"
     *   insert="false"
     *   update="false"
     * @return
     */
    @Column(name="PARENT_ENTRY_ID", insertable=false, updatable=false)
    public long getTopicId() {
        return topicId;
    }

    public void setTopicId(long topicId) {
        this.topicId = topicId;
    }

    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }

    @Transient
    public boolean isHidden() {
        return getState() == STATE_HIDDEN;
    }

    @Transient
    public boolean isCommentsDisabled() {
        return getState() == STATE_COMMENTS_DISABLED;
    }

}
